package com.zhouyy.api.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhouyy.api.entity.Fruit;
import com.zhouyy.api.mapper.FruitMapper;
import com.zhouyy.api.service.IFruitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Slf4j
public class FruitServiceImpl extends ServiceImpl<FruitMapper, Fruit> implements IFruitService {
    @Override
    public Map<Integer, Fruit> getFruitByType(List<Integer> types) {
        return this.lambdaQuery()
                .in(CollectionUtils.isNotEmpty(types), Fruit::getType, types)
                .list()
                .stream()
                .collect(Collectors.toMap(Fruit::getType, fruit -> fruit));
    }
}
